package com.vf.cloud.paas.app.master.api.file.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.vf.cloud.paas.app.master.api.file.service.IThumbnail;
import com.vf.cloud.paas.app.master.common.repository.base.Thumbnail;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController
public class ThumbnailController {

	@Autowired
	private IThumbnail thumbnailImpl;

	@GetMapping(value = "/api/v1/thumbnail/{id}", produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE })
	@ResponseBody
	public byte[] image(@PathVariable String id) {
		byte[] data = null;
		Thumbnail thumbnail = thumbnailImpl.findById(id);
		if (thumbnail != null) {
			data = thumbnail.getContent().getData();
		}
		return data;
	}

}
